//
//  GWCommonViewBaseConteoller.m
//  新浪微博
//
//  Created by qianfeng on 16/1/9.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWCommonViewBaseConteoller.h"
#import "GWMySearchBar.h"
#import "GWDiscoverItemGroup.h"
#import "GWDiscoverItem.h"
#import "GWDiscoverCell.h"
@interface GWCommonViewBaseConteoller ()
@property (nonatomic,copy)NSMutableArray *itemGroups;
@end

@implementation GWCommonViewBaseConteoller
-(NSMutableArray *)itemGroups
{
    if (_itemGroups ==nil) {
        _itemGroups =[NSMutableArray array ];
    }
    return _itemGroups;
}
-(instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.backgroundColor =GWGlobalBackgroundColor;
    
    
    self.tableView.sectionFooterHeight =10;
    self.tableView.sectionHeaderHeight =0;
    self.tableView.separatorStyle =UITableViewCellSeparatorStyleNone;
    
    
    self.tableView.contentInset =UIEdgeInsetsMake(-25, 0, 0, 0);
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.itemGroups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    GWDiscoverItemGroup *group =self.itemGroups[section];
    return group.items.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GWDiscoverItemGroup *group =self.itemGroups[indexPath.section];
    GWDiscoverCell *cell =[GWDiscoverCell discoverCellWithTableView:tableView];
    cell.item =group.items[indexPath.row];
    [cell setIndexPath:indexPath andNumberOfRows:(int)group.items.count];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    GWDiscoverItemGroup *group =self.itemGroups[indexPath.section];
    GWDiscoverItem *item =group.items[indexPath.row];
    if (item.pushClass) {
        Class class =item.pushClass;
        ;
        UIViewController *vc =[[class alloc]init];
        vc.title =item.title;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (item.operation)
    {
        item.operation();
    }
}


@end
